package com.example.aop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Slf4j
//@Component
@Aspect
@Order(2)
public class AspectDemo2 {
    @Around("com.example.aop.aspect.AspectDemo1.pointCut()")
    public Object timeRecord(ProceedingJoinPoint joinPoint) throws Throwable {
        long start = System.currentTimeMillis();
        log.info("demo2 around before");
        Object proceed = joinPoint.proceed();
        long end = System.currentTimeMillis();
        log.info("demo2 around after");
        log.info("消耗时间: " + (end - start) + " ms");
        return proceed;
    }

    @Before("com.example.aop.aspect.AspectDemo1.pointCut()")
    public void before(){
        log.info("demo2 before...");
    }

    @After("com.example.aop.aspect.AspectDemo1.pointCut()")
    public void after(){
        log.info("demo2 after...");
    }

    @AfterReturning("com.example.aop.aspect.AspectDemo1.pointCut()")
    public void afterReturning(){
        log.info("demo2 after returning...");
    }

    @AfterThrowing("com.example.aop.aspect.AspectDemo1.pointCut()")
    public void afterThrowing(){
        log.info("demo2 after throwing...");
    }
}
